/*
 * Copyright 2010-2011 Sanjay Dwivedi.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.isdinvestments.ui.richgui.vaadin.cam;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.isdinvestments.cam.application.CustomerService;
import com.isdinvestments.cam.domain.model.Customer;
import com.vaadin.data.util.BeanContainer;
import com.vaadin.data.util.BeanItem;
import com.vaadin.data.util.BeanItemContainer;

/**
 * Customer Presentation Model Customer Account Management Web interface.
 * All Customer Account Management UI logic and behavior is in this class.
 * 
 * @author Sanjay Dwivedi
 * @since 1.0
 *
 */
public class CustomerPM {
	@Autowired
	protected CustomerService customerService;
	private BeanItem<Customer> customer;
	private BeanContainer<Long, Customer> customerList = new BeanContainer<Long, Customer>(Customer.class);
	
	public CustomerPM() {
		customerList.setBeanIdProperty("id");
	}

	public void setCustomer(BeanItem<Customer> customer) {
		this.customer = customer;
	}

	public BeanItem<Customer> getCustomer() {
		return customer;
	}


	public BeanContainer<Long, Customer> getCustomerList() {
		List<Customer> customers = customerService.getAllCustomers();
		customerList.addAll(customers);
		return customerList;
	}
	
	public void removeCustomerListFilters(final String filterString) {
		customerList.removeContainerFilters(filterString);
	}

	public void addCustomerListFilter(Object propertyId,
            String filterString,
            boolean ignoreCase,
            boolean onlyMatchPrefix) {
		customerList.addContainerFilter(propertyId, filterString, ignoreCase, onlyMatchPrefix);
		
	}
	
	public int getCustomerListSize() {
		return customerList.size();
	}

}
